/**
 *
 * ......................我佛慈悲.......................
 *                       _oo0oo_
 *                      o8888888o
 *                      88" . "88
 *                      (| -_- |)
 *                      0\  =  /0
 *                    ___/`---'\___
 *                  .' \\|     |// '.
 *                 / \\|||  :  |||// \
 *                / _||||| -卍-|||||- \
 *               |   | \\\  -  /// |   |
 *               | \_|  ''\---/''  |_/ |
 *               \  .-\__  '-'  ___/-. /
 *             ___'. .'  /--.--\  `. .'___
 *          ."" '<  `.___\_<|>_/___.' >' "".
 *         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
 *         \  \ `_.   \_ __\ /__ _/   .-` /  /
 *     =====`-.____`.___ \_____/___.-`___.-'=====
 *                       `=---='
 *
 *..................佛祖开光 ,永无BUG....................
 *         CSDN博客:http://blog.csdn.net/song5347
 *       github地址:https://github.com/lingsuiderongyan
 *             邮箱:lingsuiderongyan@163.com
 */

import UIKit


extension NSAttributedString {
    
    //  通过表情模型创建表情富文本对象
    class func attributedStringWithEmoticon(emoticon: LSEmoticon, font: UIFont) -> NSAttributedString {
        
        
        //   1. 通过图片名创建一个UIImage对象
        let image = UIImage(named: emoticon.path!)
        //   2. 通过UIImage对象创建一个文本附件(NSTextAttachment)
        let attachment =  LSTextAttachment() //NSTextAttachment()
        //  设置文本附件对象的表情模型
        attachment.emoticon = emoticon
        //  获取文字的行高
        let fontHeight = font.lineHeight
        //  设置图片大小和位置, 设置bounds会影响子控件的布局
        attachment.bounds = CGRect(x: 0, y: -4, width: fontHeight, height: fontHeight)
        //  设置图片
        attachment.image = image
        //   3. 通过文本附件创建富文本(NSAttributedString)
        let attributedStr = NSAttributedString(attachment: attachment)
        
        return attributedStr

    }
 
}




